package br.poli.ecomp.sma.massim.action;

import java.util.Random;

import br.poli.ecomp.sma.massim.env.Search;
import br.poli.ecomp.sma.massim.env.WorldModel;
import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.Atom;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Term;

public class CercaPertenceCurral extends DefaultInternalAction {
	
	private static final long serialVersionUID = 1L;
	
	WorldModel.Move[] actionsOrder = new WorldModel.Move[WorldModel.nbActions];
    Random     random = new Random();
    
    public CercaPertenceCurral() {
        for (int i=0; i<WorldModel.nbActions; i++) {
            actionsOrder[i] = Search.defaultActions[i];
        }
    }
	
//	public enum Move {
//        north, south, east, west, northeast, southeast, northwest, southwest, skip 
//    };


	@Override
	public Object execute(TransitionSystem ts, Unifier un, Term[] terms)
			throws Exception {
		Term cx1 = terms[0];
		Term cy1 = terms[1];
		Term cx2 = terms[2];
		Term cy2 = terms[3];
		Term ex1 = terms[4];
		Term ey1 = terms[5];
		Term fx1 = terms[6];
		Term fy1 = terms[7];
		Term resp = terms[8];
		
		double vcx1 = ((NumberTerm)cx1).solve();
		double vcy1 = ((NumberTerm)cy1).solve();
		double vcx2 = ((NumberTerm)cx2).solve();
		double vcy2 = ((NumberTerm)cy2).solve();
		double vex1 = ((NumberTerm)ex1).solve();
		double vey1 = ((NumberTerm)ey1).solve();
		double vfx1 = ((NumberTerm)fx1).solve();
		double vfy1 = ((NumberTerm)fy1).solve();
		
		double tamanhoHorizonatalCurral = vcx2 - vcx1;
    	double tamanhoVerticalCurral = vcy2 - vcy1;
    	if((Math.abs(vfx1 - vex1) < tamanhoHorizonatalCurral) && 
    			(Math.abs(vfy1 - vey1) < tamanhoVerticalCurral)){
    		 return un.unifies(resp, new Atom("true"));
    	}
    	else{
    		return un.unifies(resp, new Atom("false"));
    	}
		
	}
}
